var _pt_code = "2"; //pt_code = 2 = Branding & Marketing
//pt_code = 1 = New Media

var _pt_category = "";
var _pt_date = "";
var _pt_tag = "";
var _pt_keyword = "";
var _prjCode = "";
var category_class;

var paging_num = 0;
var paging_num_group = 0;
var paging_plus = 0;

var popupIs = new String();

var UserAgent = navigator.userAgent;

// 공통 Paging
var common = {
    page: function(param) {
        frmParams.currentPage.value = param;
        frmParams.submit();
    }
}

// Sns 공유 function
var sns_share = {
        share: function(type) {
            var host = location.host;
            var img_src = $(".work_pop" + category_class + "").find(".work_pop_con>img").attr("src");
            var name = $(".work_pop" + category_class + "").find(".work_pop_head_inner>h2").text();
            var caption = $(".work_pop" + category_class + "").find(".work_pop_head_inner>p").text();
            var desc = "";

            if (category_class == "_old") {
                desc = $(".work_pop" + category_class + "").find(".old_after>p").text();
            } else {
                desc = $(".work_pop" + category_class + "").find(".mul").text();
            }

            var w = 580,
                h = 270,
                winl = (screen.width - w) / 2,
                wint = (screen.height - h) / 2;

            if (type == "F") {
                var link = host + '/Work/#' + getPtCodeText(_pt_code) + '/' + _prjCode + '/';
                //window.open("//www.facebook.com/sharer.php?u="+link+"","facebook_pop","resizable=no, copyhistory=no, toolbar=no, menubar=no, width=" + w + ",height=" + h + ",top=" + wint + ",left=" + winl + "");

                FB.ui({
                        method: 'feed',
                        name: name,
                        caption: caption,
                        description: desc,
                        link: link,
                        picture: host + img_src
                    },
                    function(response) {
                        if (response && response.post_id) {
                            alert('공유 완료가 완료되었습니다.');
                        }
                    }

                );
            } else {
                window.open("//twitter.com/intent/tweet?url=" + location.protocol + "//" + host + "/Work/%23" + getPtCodeText(_pt_code) + "/" + _prjCode + "/&text=" + name + "", "Vinyl-i:TwitterShare", "resizable=no, copyhistory=no, toolbar=no, menubar=no, width=" + w + ",height=" + h + ",top=" + wint + ",left=" + winl + "");
            }
        }
    }

//Ajax List
function ajax_list(type) {
    $.ajax({
        type: "GET",
        cache: false,
        dataType: "json",
        data: {
            pt_code: _pt_code,
            pt_category: _pt_category,
            pt_date: _pt_date,
            pt_tag: _pt_tag,
            pt_keyword: _pt_keyword
        },
        url: "/Ajax/work_test/workList.json",
        success: function(data) {
            if (type == "list") {
                $(".contents" + _pt_code + "").empty();
            }

            if (paging_num == 0) {
                paging_plus = 14;
            } else {
                paging_plus = 15;
            }

            var paging_change = data.vinyl_data.length - $(".contents" + _pt_code + ">.work_sec").length

            if (paging_change < 15) {
                paging_num_group = $(".contents" + _pt_code + ">.work_sec").length;
                paging_plus = paging_change;
            }

            for (var i = paging_num_group; i < paging_num_group + paging_plus; i++) {
                var project_isRecent = data.vinyl_data[i].vw_isRecent;
                var project_Name = data.vinyl_data[i].vw_projectName;
                var project_Code = data.vinyl_data[i].vw_prjCode;
                var project_Date = data.vinyl_data[i].vw_startDate;
                var project_Tag = data.vinyl_data[i].vw_projectTag;
                var project_ThumImg = data.vinyl_data[i].thum_filenameSaved;
                var project_Client = data.vinyl_data[i].cl_name;

                rowSection = "<section class='work_sec motion_data' prjCode=" + project_Code + ">";
                rowSection += "<span class='work_newIcon' style='display:" + project_Recent(project_isRecent) + "'>" + category_recentImg(_pt_code) + "</span>";
                rowSection += "<div class='work_sec_contents_wrap'>";
                rowSection += "<a href='#" + pt_code_NameGet(_pt_code) + "/" + project_Code + "'><img src='/resources/UploadFiles/Project/Thumb/" + project_ThumImg + ".jpg' onerror=this.src='/resources/image/noimage.png' alt='' style='opacity: 1;'></a>";
                rowSection += "<div class='work_secHead'>";
                rowSection += "<h2><a href='#none'>" + PrjName_Tag(project_Name, "name", device_type()) + "</a></h2>"
                rowSection += "<p class='date'>" + project_Date + "</p>";
                rowSection += "</div>";
                rowSection += "<p class='m_text'>" + project_Client.toUpperCase() + "</p>";
                rowSection += "</section>";

                if (type == "list") {
                    $(".contents" + _pt_code + "").append(rowSection);
                } else {
                    $(".contents" + _pt_code + ">.mob_hide").before(rowSection);
                }
            }

            if (data.vinyl_data.length > $(".contents" + _pt_code + ">.work_sec").length && $(".contents" + _pt_code + ">.mob_hide").length == 0) {
                rowAddBtn = "<section class='mob_hide'>";
                rowAddBtn += "<a href='#none'><img src='/resources/image/plus_secton_more.jpg' alt='' /></a>";
                rowAddBtn += "</section>";
                $(".contents" + _pt_code + "").append(rowAddBtn);
            }

            if (data.vinyl_data.length == $(".contents" + _pt_code + ">.work_sec").length) {
                $(".contents" + _pt_code + ">.mob_hide").hide();
            }

            $(".contents" + _pt_code + "").show();
            $(".contents" + _pt_code + ">.mob_hide").unbind();
            ajax_list_add_btn();
            pop_layer();
            dim_click();
            thumbHover();
            delay_animation();
            paging_num++;
            paging_num_group = paging_num_group + paging_plus;
        }
    });
}

//Ajax NewsLetter List
function newsletter_ajax_list() {
    $.ajax({
        type: "GET",
        cache: false,
        dataType: "json",
        url: "/Ajax/vNewsLetterList.aspx",
        success: function(data) {
            var rowSection = "";

            if (data.vinyl_data.length == 0) {
                $(".newsletter_article").append("<div style='width:100%;text-align:center;'>등록된 뉴스레터가 없습니다.</div>");
            } else {
                for (var i = 0; i < data.vinyl_data.length; i++) {
                    var subject = data.vinyl_data[i].subject;
                    var thumb_image = data.vinyl_data[i].thumb_image;
                    var pdf_uploadfiles = data.vinyl_data[i].pdf_uploadfiles;

                    rowSection = "<section class='newsletter_sec'>";
                    rowSection += "<div class='newsletter_sec_contents_wrap'>";
                    rowSection += "<a href='#' title='" + subject + " 다운 받기'><img src='/resources/UploadFiles/NewsLetter/Thumb/" + thumb_image + "' alt='" + subject + " 썸네일 이미지'></a>";
                    rowSection += "<div>";
                    rowSection += "<h1>" + subject + "</h1>";
                    rowSection += "<a href='http://" + location.host + "/resources/UploadFiles/NewsLetter/PDF/" + pdf_uploadfiles + "' title='" + subject + " 다운 받기'><img src='/resources/image/newsletterPDF.png' alt='" + subject + " PDF 다운받기 버튼'></a>";
                    rowSection += "</div>";
                    rowSection += "</div>";
                    rowSection += "</section>";

                    $(".newsletter_article").append(rowSection);
                }
            }
        }
    });
}

//Ajax View
function checkEmail(val) {
        // console.log(val)
        var reg = /^((\w|[\-\.])+)@((\w|[\-\.])+)\.([A-Za-z]+)$/;
        if (val.search(reg) != -1) {
            return false;
            //
        }
        return true;
        // 
    }
    // end checkEmail(val)

function checkNum(target, e) {
        var chars = "0123456789",
            num = target.value.substr(target.value.length - 1);

        if (chars.indexOf(num) == -1) {
            alert("숫자만 입력하여 주세요.");
            target.value = target.value.substr(0, target.value.length - 1);
        }
    }
    // end checkNum

function checkForm() {

}

//뉴스레터 구독 등록
function newsletter_sub_insert() {
    var $NewsletterRegist = $('#NewsletterRegist'),
        $username = $('#user_name'),
        $useremail = $('#user_email'),
        $usercompany = $('#user_company'),
        $userposition = $('#user_position');

    if ($username.val() == "") {
        alert("이름 입력칸은 필수 입력 사항입니다.");
        $username.focus();
        return;
    }
    // id가 username인 입력란 체크

    if (checkEmail($useremail.val())) {
        alert("이메일 주소 형식이 잘못 되었습니다.")
        $useremail.focus();
        return;
    }
    //이메일 주소 유효성 검사

    if ($usercompany.val() == "") {
        alert("회사 입력칸은 필수 입력 사항입니다.");
        $usercompany.focus();
        return;
    }
    //회사 정보 입력 검사

    // console.log('모두 입력 완료')

    $.ajax({
        type: "POST",
        cache: false,
        dataType: "json",
        data: {
            user_email: $("#user_email").val(),
            user_name: $("#user_name").val(),
            user_company: $("#user_company").val(),
            user_position: $("#user_position").val()
        },
        url: "/ajax/ajax_NewsLetterSubscriber.aspx",
        success: function(data) {
            if (data.result == "S") {
                // console.log("등록완료");
                alert($useremail.val() + " 메일 주소로 뉴스레터 등록 신청이 완료되었습니다.")
            } else {
                alert($useremail.val() + " 메일 주소는 이미 뉴스레터 등록 신청이 된 상태입니다.");
            }
        }
    });
}

function pt_code_NameGet(type) {
    var temp_name;
    if (type == 1) {
        temp_name = "vlab"
    } else {
        temp_name = "vcomm"
    }

    return temp_name;
}

//Recent 이미지
function category_recentImg(category_type) {
    var img_src = "";
    if (category_type == "2") {
        img_src = "<img src='/resources/image/icon/recent_vcomm.png' alt='' />";
    } else {
        img_src = "<img src='/resources/image/icon/recent_vlab.png' alt='' />";
    }
    return img_src;
}

function motionPopup(e, val, num) {
        var _event = e,
            _category_class = val,
            _settNum = num,
            $work_dim = $(".work_dim"),
            $work_pop = $(".work_pop" + _category_class + ""),
            $work_pop_head = $('.work_pop_head'),
            $product_pop = $(".product_pop"),
            $press_view_pop = $('.press_view_pop'),
            $vimeo_pop = $(".vimeo_pop"),
            $product_pop_head = $('.product_pop_head'),
            $sortType2 = $("#sortType2"),
            windowHeight = $(window).height(),
            windowInWidth = $(window).innerWidth(),
            body = $("html, body"),
            speed = 500;

        if (_event == "open") {
            $work_dim.stop().show().animate({
                'opacity': '0.8'
            }, speed + 250, 'easeOutQuint');
            $work_pop.css("top", windowHeight - 100 + 'px').animate({
                'top': '60px'
            }, speed - 150, 'easeOutQuint');
            $work_pop_head.css("top", "-90px").animate({
                'top': '0'
            }, speed - 100, 'easeOutQuint').find('p').css("opacity", "0").stop().delay(speed - 200).animate({
                "opacity": "1"
            }, speed - 100, 'easeOutQuint');
            if (!$('#represent_Vimeo_Movie').length > 0) {
                //$('.vimeoWrap').hide();
            }
        } else if (_event == "open_product") {
            $sortType2.hide();
            $work_dim.stop().show().animate({
                'opacity': '0.8'
            }, speed + 250, 'easeOutQuint');
            $product_pop.css("top", windowHeight).animate({
                'top': '60px'
            }, speed - 150, 'easeOutQuint');
            $product_pop_head.css("top", "-90px").animate({
                'top': '0'
            }, speed - 100, 'easeOutQuint');

        } else if (_event == "open_press") {
            // console.log('프레스 클릭')
            $work_dim.stop().show().animate({
                'opacity': '0.8'
            }, speed + 250, 'easeOutQuint');
            $press_view_pop.css("top", windowHeight).animate({
                'top': '0px'
            }, speed - 150, 'easeOutQuint');
            // $product_pop_head.css("top", "-90px").animate({ 'top': '0' }, speed-100, 'easeOutQuint');

        } else if (_event == "open_vimeo") {
            $work_dim.stop().show().animate({
                'opacity': '0.8'
            }, speed + 250, 'easeOutQuint');
            $vimeo_pop.css({
                'top': '50%',
                'height': 0
            }).animate({
                'top': '60px',
                'height': parseInt($vimeo_pop.css("width")) / 1.77
            }, speed - 150, 'easeOutQuint');

        } else if (_event == "close") {
            $work_dim.stop().animate({
                'opacity': '0'
            }, speed + 250, 'easeInQuint', function() {
                $work_dim.hide();
                dimclick = 0;
            });
            $work_pop.stop().animate({
                'top': windowHeight
            }, speed - 150, 'easeInQuint', function() {
                $work_pop.empty(); //work_pop 초기화.
                body.stop().animate({
                    scrollTop: _settNum
                }, 400, 'easeOutQuint');
            });
            $work_pop_head.stop().animate({
                'top': "-90px"
            }, speed - 100, 'easeInQuint').find('p').css("opacity", "1").stop().animate({
                "opacity": "0"
            }, speed - 100, 'easeOutQuint');;
        } else if (_event == "close_press") {
            $work_dim.stop().animate({
                'opacity': '0'
            }, speed + 250, 'easeInQuint', function() {
                $work_dim.hide();
                dimclick = 0;
            });
            $press_view_pop.stop().animate({
                'top': windowHeight
            }, speed - 150, 'easeInQuint', function() {
                $press_view_pop.empty();
                $(".pressList").show();
                body.stop().animate({
                    scrollTop: _settNum
                }, 400, 'easeOutQuint');
            });
        } else if (_event == "close_product") {
            if (popupIs == "vimeo") {
                $vimeo_pop.stop().animate({
                    'top': '50%',
                    'height': 0
                }, speed - 150, 'easeInQuint', function() {
                    $vimeo_pop.empty(); //work_pop 초기화.
                    $vimeo_pop.hide();
                    body.stop().animate({
                        scrollTop: _settNum
                    }, 400, 'easeOutQuint');
                    popupIs == "none";
                });
            } else {
                $sortType2.show();

                if ($product_pop.css('display') == 'block') {
                    $product_pop.stop().animate({
                        'top': windowHeight
                    }, speed - 150, 'easeInQuint', function() {
                        $product_pop.empty(); //work_pop 초기화.
                        $product_pop.hide();
                        body.stop().animate({
                            scrollTop: _settNum
                        }, 400, 'easeOutQuint');
                    });
                    $product_pop_head.stop().animate({
                        'top': "-90px"
                    }, speed - 100, 'easeInQuint');
                } else if ($work_pop.css('display') == 'block') {
                    // related list
                    $work_pop.stop().animate({
                        'top': windowHeight
                    }, speed - 150, 'easeInQuint', function() {
                        $work_pop.empty(); //work_pop 초기화.
                        body.stop().animate({
                            scrollTop: _settNum
                        }, 400, 'easeOutQuint');
                    });
                    $work_pop_head.stop().animate({
                        'top': "-90px"
                    }, speed - 100, 'easeInQuint');
                }
                //if display
            }
            //if vimeo
            $work_dim.stop().animate({
                'opacity': '0'
            }, speed + 250, 'easeInQuint', function() {
                $work_dim.hide();
                dimclick = 0;
            });
        }
        //if
        if (_category_class == "vimeo") {
            popupIs = "vimeo";
        } else {
            popupIs = "none";
        }

    }
    //motionPopup

function ajax_view(prjCode) {

    _prjCode = prjCode;
    _pt_date = "";
    _pt_keyword = "";
    _pt_category = "";
    _pt_tag = "";
    settNum = $(window).scrollTop();
    dimclick = 0;

    // Log Insert
    vi_log_save.click("work", _pt_code, _pt_category, _pt_tag, _pt_date, _pt_keyword, _prjCode, "");

    $(".work_pop" + category_class + "").find(".wppr_text>ul").empty();

    var ajax_url;


    if (prjCode == "0072" || prjCode == "0071" || prjCode == "0067" || prjCode == "0065" || prjCode == "0066" || prjCode == "0049" || prjCode == "0048" || prjCode == "0047" || prjCode == "0062" || prjCode == "0043" || prjCode == "0069" || prjCode == "0068" || prjCode == "0057" || prjCode == "0064" || prjCode == "0052" || prjCode == "0070" || prjCode == "0063" || prjCode == "0073" || prjCode == "0059" || prjCode == "0044" || prjCode > "0073") {
        category_class = "";
        ajax_url = "";
    } else {
        category_class = "_old";
        ajax_url = "_Old";
    }
    $.ajax({
        type: "GET",
        dataType: "html",
        cache: false,
        contentType: "application/json; charset=utf-8",
        data: {
            vw_prjCode: prjCode
        },
        url: "/Ajax/work_test/vWorkView" + ajax_url + ".html",
        success: function(data) {
            $(document).scrollTop(0);
            /* Common */

            /* Work Section */
            $(".work_pop" + category_class + "").html(data);
            $(".work_pop" + category_class + "").show();
            motionPopup('open', category_class, settNum);
            $(".work_article").hide();

            /* Product Section */
            $(".product_article").hide();
            $(".related_list").hide();
            $(".product_list").hide();

            //vimeo 영상 resize
            var $vimeoWrap = $('#vimeoWrap'),
                vimeoWidth = $vimeoWrap.width(),
                vimeoHeight = vimeoWidth / 1.77;

            window.onresize = function(event) {
                vimeoWidth = $vimeoWrap.width(),
                vimeoHeight = vimeoWidth / 1.77;
            }

            //closeAction
            $('.con_close').bind('click', function() {
                closeAction("close");
            });
        }
    });
}

//Product View
//Todo : Work View 닫기 버튼 공통으로 묶기.
function product_view(_tabIndex) {
        settNum = $(window).scrollTop();
        dimclick = 0;
        $.ajax({
            type: "GET",
            dataType: "html",
            cache: false,
            contentType: "application/html; charset=utf-8",
            data: {
                tabIndex: _tabIndex
            },
            url: "/Ajax/vProductView.aspx",
            success: function(data) {
                $(document).scrollTop(0);

                $(".product_article").hide();
                $(".related_list").hide();
                $(".product_list").hide();

                $(".product_pop").html(data);
                $(".product_pop").show();
                motionPopup('open_product', "", settNum);

                $('.con_close').bind('click', function() {
                    closeAction("close_product");
                });
            }
        });
    }
    //press view
function press_view(_np_seq) {
        //Scroll때문에 리스트 숨김.
        $(".pressList").hide();
        settNum = $(window).scrollTop();
        dimclick = 0;
        $.ajax({
            type: "GET",
            dataType: "html",
            cache: false,
            contentType: "application/json; charset=utf-8",
            data: {
                np_seq: _np_seq
            },
            url: "/Ajax/work_test/pressView.html",
            success: function(data) {
            	
                $(".press_view_pop").show();
                $(".press_view_pop").html(data);
                motionPopup('open_press', "", settNum);
                $('.press_con_close').bind('click', function() {
                    closeAction("close_press");
                });
                //click
                dim_click();

            }
        });
    }
    //press view
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/gi, "");
}

//Line Up List
function line_up(data_category) {
    s = data_category;
    var relation_project_arry = s.split(',');
    var product_num = 0;

    //카테고리별 ProductList
    $.getJSON("/Ajax/work_test/productList.json", function(data) {
        for (j = 0; j < data.pro_main.length; j++) {
            for (i = 0; i < relation_project_arry.length; i++) {
                if (relation_project_arry == data.pro_main[j].category) {
                    product_num++;

                    relation_rowSection = "<li class='clearfix' data-index=" + data.pro_main[j].tabIndex + ">";
                    relation_rowSection += "<dl><dt class='dtnumber'>0" + product_num + "</dt>";
                    relation_rowSection += "<dt class='dtname'>" + data.pro_main[j].title + "</dt>";
                    relation_rowSection += "<dd>" + data.pro_main[j].title_desc + "</dd></dl>";
                    relation_rowSection += "<div class='thumb'><a href=javascript:product_view(" + data.pro_main[j].tabIndex + ") title='" + data.pro_main[j].title + " 자세히 보기'><img src='/resources/image/product/pro_" + j + ".png' alt=''></a></div></li>";

                    $(".product_list>ul").append(relation_rowSection);
                }
            }
        }
    });
}

function line_up_all(data_category, idx) {
    s = data_category;
    var relation_project_arry = s.split(',');
    var product_num = 0;

    //카테고리별 ProductList
    $.getJSON("/Ajax/work_test/productList.json", function(data) {
        for (j = 0; j < data.pro_main.length; j++) {
            for (i = 0; i < relation_project_arry.length; i++) {
                if (relation_project_arry == data.pro_main[j].category) {
                    product_num++;

                    relation_rowSection = "<li class='clearfix' data-index=" + data.pro_main[j].tabIndex + ">";
                    relation_rowSection += "<dl><dt class='dtnumber'>0" + product_num + "</dt>";
                    relation_rowSection += "<dt class='dtname'>" + data.pro_main[j].title + "</dt>";
                    relation_rowSection += "<dd>" + data.pro_main[j].title_desc + "</dd></dl>";
                    relation_rowSection += "<div class='thumb'><a href=javascript:product_view(" + data.pro_main[j].tabIndex + ") title='" + data.pro_main[j].title + " 자세히 보기'><img src='/resources/image/product/pro_" + j + ".png' alt=''></a></div></li>";

                    $(".lineup0" + idx + ">ul").append(relation_rowSection);
                }
            }
        }
    });
}

//관련 프로젝트
function related_project(category) {
	
	/*
    //카테고리별 ProductList
    $.getJSON("/Ajax/work_test/relatedProject.aspx?vw_projectMainCategory=" + category + "", function(data) {
        for (i = 0; i < data.vinyl_related_project.length; i++) {
            $('.related_list').append("<section class='work_sec' vw_prjcode=" + data.vinyl_related_project[i].vw_prjCode + " ><span class='work_newIcon' style='display:" + project_Recent(data.vinyl_related_project[i].vw_isRecent) + "'><img src='/resources/image/icon/recent.png' alt=''></span><div class='work_sec_contents_wrap'><a href=javascript:ajax_view('" + data.vinyl_related_project[i].vw_prjCode + "')><img src=/resources/UploadFiles/Project/Thumb/" + data.vinyl_related_project[i].thum_filenameSaved + " onerror=this.src='/resources/image/noimage.png' alt='' style='opacity: 1;'></a><div class='work_secHead'><h2><a href='#none'>" + PrjName_Tag(data.vinyl_related_project[i].vw_projectName, "name", device_type()) + "</a></h2><p class='date'>" + data.vinyl_related_project[i].vw_startDate + "</p></div><p class='m_text'>Vinyl I</p></div></section>");

        }
    });
    */
	
	//카테고리별 ProductList
    $.getJSON("/Ajax/work_test/relatedProject.json", function(data) {
        for (i = 0; i < data.vinyl_related_project.length; i++) {
            $('.related_list').append("<section class='work_sec' vw_prjcode=" + data.vinyl_related_project[i].vw_prjCode + " ><span class='work_newIcon' style='display:" + project_Recent(data.vinyl_related_project[i].vw_isRecent) + "'><img src='/resources/image/icon/recent.png' alt=''></span><div class='work_sec_contents_wrap'><a href=javascript:ajax_view('" + data.vinyl_related_project[i].vw_prjCode + "')><img src=/resources/UploadFiles/Project/Thumb/" + data.vinyl_related_project[i].thum_filenameSaved + " onerror=this.src='/resources/image/noimage.png' alt='' style='opacity: 1;'></a><div class='work_secHead'><h2><a href='#none'>" + PrjName_Tag(data.vinyl_related_project[i].vw_projectName, "name", device_type()) + "</a></h2><p class='date'>" + data.vinyl_related_project[i].vw_startDate + "</p></div><p class='m_text'>Vinyl I</p></div></section>");

        }
    });
	
    dim_click();
}

function video_player(src, id, img) {
    jwplayer(id).setup({
        file: '/resources/UploadFiles/' + src + '',
        image: '/resources/UploadFiles/' + img + '',
        width: '100%',
        aspectratio: '16:9',
        fallback: 'false',
        primary: 'flash'
    });
}

//프로젝트 카테고리 명 변경.
function category_replace(param) {
    var str;
    if (param == null) {
        str = "";
    } else {
        str = param.replace("0", "Brand Experience").replace("1", "Digital Promotion").replace("2", "IMC Campaign").replace("3", "Interactive New Media").replace("4", "Social Campaign").replace("5", "Consulting & Service UX").replace("6", "Digital Space").replace("7", "Exhibition & Expo").replace("8", "Art & Performance").replace("9", "Advertising platform").replace("10", "Retail & Marketing");
    }
    return str;
}

//프로젝트 기간별로 ReCent설정.
function project_Recent(isRecent) {
    if (isRecent == "N") {
        visible = "none";
    } else {
        visible = "";
    }
    return visible;
}

//현재 Device 종류
function device_type() {
    var winwt = $(window).width();
    var type;

    if (winwt < 768) {
        type = "Mobile1";
    } else if (winwt >= 768 && winwt < 1024) {
        type = "Mobile2";
    } else if (winwt >= 1024 && winwt < 1280) {
        type = "PC1";
    } else if (winwt >= 1280 && winwt < 1420) {
        type = "PC2";
    } else if (winwt >= 1420) {
        type = "PC3";
    }
    return type;
}

//현재 Device에 따른 Project & Tag 길이 변경.
function PrjName_Tag(str, type, device) {
    var edit_str;

    //Type이 Tag면 Else면 Name
    if (type == "tag") {
        switch (device) {
            case "Mobile1":
                if (str == null) {
                    edit_str = "&nbsp;";
                } else if (str.length <= 40) {
                    edit_str = str;
                } else {
                    edit_str = str.substring(0, 40) + "...";
                }
                break;
            case "Mobile2":
                if (str == null) {
                    edit_str = "&nbsp;";
                } else if (str.length <= 40) {
                    edit_str = str;
                } else {
                    edit_str = str.substring(0, 40) + "...";
                }
                break;
            case "PC2":
                if (str == null) {
                    edit_str = "&nbsp;";
                } else if (str.length <= 50) {
                    edit_str = str;
                } else {
                    edit_str = str.substring(0, 50) + "...";
                }
                break;
            default:
                if (str == null) {
                    edit_str = "&nbsp;";
                } else if (str.length <= 70) {
                    edit_str = str;
                } else {
                    edit_str = str.substring(0, 70) + "...";
                }
                break;
        }
        return edit_str;
    } else {
        //디자인 변경으로 문자열 자르지 않음. 전체 공통 50자. 혹시 몰라 코드는 남겨놓음.
        switch (device) {
            case "Mobile1":
                if (str == null) {
                    edit_str = "&nbsp;";
                } else if (str.length <= 50) {
                    edit_str = str;
                } else {
                    edit_str = str.substring(0, 50) + "...";
                }
                break;
            case "Mobile2":
                if (str == null) {
                    edit_str = "&nbsp;";
                } else if (str.length <= 50) {
                    edit_str = str;
                } else {
                    edit_str = str.substring(0, 50) + "...";
                }
                break;
            case "PC2":
                if (str == null) {
                    edit_str = "&nbsp;";
                } else if (str.length <= 50) {
                    edit_str = str;
                } else {
                    edit_str = str.substring(0, 50) + "...";
                }
                break;
            default:
                if (str == null) {
                    edit_str = "&nbsp;";
                } else if (str.length <= 50) {
                    edit_str = str;
                } else {
                    edit_str = str.substring(0, 50) + "...";
                }
                break;
        }
        return edit_str;
    }

}

function getHashType(hash_type, hash_prjCode) {
    if (hash_type == false) {
        ajax_view(hash_prjCode);
    }
}

function getPtCodeText(type) {
    var str;

    if (type == 1) {
        str = "vlab";
    } else {
        str = "vcomm";
    }
    return str;
}

//List Add Btn 클릭
function ajax_list_add_btn() {
    $(".mob_hide").bind("click", function() {
        ajax_list("add");
        check_slide($(this));
    });
    
}

function dim_click() {
    var $work_dim = $('.work_dim'),
        _event;
    if (this_file == "work") {
        _event = "close";
    } else if (this_file == "product") {
        _event = "close_product";
    } else if (this_file == "press") {
        _event = "close_press";
    }
    $work_dim.click(function() {
        dimclick = dimclick + 1;
        if (dimclick == 1) {
            closeAction(_event);
        }
    });
    //click
}

function pop_layer() {
        $(".work_sec").each(function(i) {
            var isView = $(this).attr("h");
            if (typeof isView == "undefined") {
                $(this).click(function() {
                    var prjCode = $(this).attr("prjcode");
                    ajax_view(prjCode);
                });
            }
        });
    }
    // var $work_dim = ;
function closeAction(e) {
    var _event = e;
    $('#wrap').css({
        'position': 'relative',
        'top': '0',
        'left': '0',
        'margin-left': '0'
    });
    if (_event == "close") {
        motionPopup('close', category_class, settNum);
    } else if (_event == "close_product") {
        motionPopup('close_product', category_class, settNum);
    } else if (_event == "close_press") {
        motionPopup('close_press', category_class, settNum);
    }

    //if

    $('.work_article').show();
    $('footer').show();
    $(".product_article").show();
    $(".related_list").show();
    $(".product_list").show();
}

function workdim() {


};
//Tag 검색 클릭		
function tag_search_list() {

    $(".category_list2>li").each(function(i) {
        $(this).click(function() {

            paging_num = 0;
            paging_num_group = 0;
            paging_plus = 0;

            //날짜를 제외한 검색 초기화.
            _pt_category = "";
            _pt_date = "";
            _pt_keyword = "";
            _prjCode = "";

            _pt_tag = $(this).attr("tag");

            // Log Insert
            vi_log_save.click("work", _pt_code, _pt_category, _pt_tag, _pt_date, _pt_keyword, _prjCode, "");

            ajax_list("list");

        });
    });
}


//Date 검색 클릭
function date_search_list() {

    $(".category_list3>li").each(function(i) {
        $(this).click(function() {

            paging_num = 0;
            paging_num_group = 0;
            paging_plus = 0;

            //날짜를 제외한 검색 초기화.
            _pt_category = "";
            _pt_tag = "";
            _pt_keyword = "";
            _prjCode = "";

            _pt_date = $(this).attr("max-date");

            // Log Insert
            vi_log_save.click("work", _pt_code, _pt_category, _pt_tag, _pt_date, _pt_keyword, _prjCode, "");

            ajax_list("list");

        });
    });
}

//문자열 길이
function getTextLength(str) {
    var len = 0;
    for (var i = 0; i < str.length; i++) {
        if (escape(str.charAt(i)).length == 6) {
            len++;
        }
        len++;
    }
    return len;
}

//Thumbnail Hover
function thumbHover() {
    $(".work_sec").each(function(i) {
        var img_src = $(this).find(".work_sec_contents_wrap").find("img").attr("src").replace("/resources/UploadFiles/Project/Thumb/", "");
        var img_arry = img_src.split('.');

        $(this).find(".work_sec_contents_wrap").find("img").attr("original", "/resources/UploadFiles/Project/Thumb/" + img_arry[0] + "." + img_arry[1]);
        $(this).find(".work_sec_contents_wrap").find("img").attr("cover", "/resources/UploadFiles/Project/Thumb/" + img_arry[0] + "_cover." + img_arry[1]);
        if ($(this).attr("h") != "o") {
            $(".work_sec").hover(function() {
                $(this).find(".work_sec_contents_wrap").find("img").attr("src", $(this).find(".work_sec_contents_wrap").find("img").attr("cover"));
            }, function() {
                $(this).find(".work_sec_contents_wrap").find("img").attr("src", $(this).find(".work_sec_contents_wrap").find("img").attr("original"));
            });
            $(this).attr("h", "o");
        }
    });
}

//NewsLetter 신청 폼 검사
function NewsLetter_form_validator() {
    var fullname = document.getElementById("fullname");
    var company = document.getElementById("company");
    var email = document.getElementById("email");

    if (fullname.value == "") {
        alert("name을 입력하세요");
        fullname.focus();
        return false;
    }
    if (company.value == "") {
        alert("Company를 입력하세요");
        company.focus();
        return false;
    }
    if (email.value == "") {
        alert("email을 입력하세요");
        email.focus();
        return false;
    } else {
    	//이메일 정규식 
        re = /[0-9a-zA-Z][_0-9a-zA-Z-]*@[_0-9a-zA-Z-]+(\.[_0-9a-zA-Z-]+){1,2}$/;

        if (email.value.length < 6 || !email.value.match(re)) {
            alert("이메일 형식이 맞지 않습니다.");
            email.focus();
            return false
        } else {
            return true;
        }
    }
    return true;
}

//NewsLetter 거부 폼 검사
function NewsLetter_cancel_form_validator() {
    var email = document.getElementById("email");

    if (email.value == "") {
        alert("email을 입력하세요");
        email.focus();
        return false;
    } else {
        re = /[0-9a-zA-Z][_0-9a-zA-Z-]*@[_0-9a-zA-Z-]+(\.[_0-9a-zA-Z-]+){1,2}$/;

        if (email.value.length < 6 || !email.value.match(re)) {
            alert("이메일 형식이 맞지 않습니다.");
            email.focus();
            return false
        } else {
            return true;
        }
    }
    return true;
}

function search_valReset() {
    $(".search").val("");
}

$(document).ready(function() {
    var rowSection = "";
    var rowAddBtn = "";
    var $loadingImg = $('#loadingImg');

    //AjaxSetup 공통
    $.ajaxSetup({
        beforeSend: function() {
            // console.log("ajax_start");
            $loadingImg.show();
        },
        complete: function() {
            // console.log("ajax_end");
            $loadingImg.hide();
        }
    });

    //검색 Click
    $(".search").keydown(function(e) {
        if (e.keyCode == 13) $("#search_btn").click();
    });

    //popup ESC 키
    $(document).keyup(function(e) {
        if (e.keyCode == 27) {
            if ($(".work_pop").is(":visible") || $(".work_pop_old").is(":visible")) {
                $(".con_close").click();
            }
        }
    });

    //Window Resize시 태그,프로젝트명 줄이기.
    $(window).resize(function() {
        $(".work_secHead>h2").each(function() {
            $(this).text(PrjName_Tag($(this).text(), "name", device_type()));
        });
        $(".m_text").each(function() {
            $(this).text(PrjName_Tag($(this).text(), "tag", device_type()));
        });
    });

    //Vcomm 카테고리 클릭.
    $(".comm_category>li").each(function(i) {
        $(this).click(function() {

            //카테고리를 제외한 검색 초기화.
            _pt_date = "";
            _pt_tag = "";
            _pt_keyword = "";
            _prjCode = "";

            paging_num = 0;
            paging_num_group = 0;
            paging_plus = 0;

            if (i == 0) {
                _pt_category = "";
            }
            if (i == 1) {
                _pt_category = "0";
            } //Branded Contents
            if (i == 2) {
                _pt_category = "1";
            } //Digital Promotion
            if (i == 3) {
                _pt_category = "2";
            } //IMC Campagin
            if (i == 4) {
                _pt_category = "3";
            } //Interactive New Media
            if (i == 5) {
                _pt_category = "4";
            } //Social Marketing

            // Log Insert
            vi_log_save.click("work", _pt_code, _pt_category, _pt_tag, _pt_date, _pt_keyword, _prjCode, "");
            search_valReset();
            ajax_list("list");

        });
    });

    //Vlab 카테고리 클릭.
    $(".lab_category>li").each(function(i) {
        $(this).click(function() {

            //카테고리를 제외한 검색 초기화.
            _pt_date = "";
            _pt_tag = "";
            _pt_keyword = "";
            _prjCode = "";

            paging_num = 0;
            paging_num_group = 0;
            paging_plus = 0;

            if (i == 0) {
                _pt_category = "";
            }
            if (i == 1) {
                _pt_category = "5";
            } //Consulting & Service UX
            if (i == 2) {
                _pt_category = "6";
            } //Digital Space
            if (i == 3) {
                _pt_category = "7";
            } //Exhibition & Expo
            if (i == 4) {
                _pt_category = "8";
            } //Art & Performance
            if (i == 5) {
                _pt_category = "9";
            } //Advertising Platform

            // Log Insert
            vi_log_save.click("work", _pt_code, _pt_category, _pt_tag, _pt_date, _pt_keyword, _prjCode, "");
            search_valReset();
            ajax_list("list");

        });
    });

    //키워드 검색 클릭		
    $("#search_btn").click(function() {
        var $searchWrap = $('.searchWrap'),
            $category = $('.category'),
            $overlayForSearch = $('.overlayForSearch');

        paging_num = 0;
        paging_num_group = 0;
        paging_plus = 0;

        //날짜를 제외한 검색 초기화.
        _pt_category = "";
        _pt_tag = "";
        _pt_date = "";
        _prjCode = "";

        _pt_keyword = $(".search").val();

        //Log Insert
        vi_log_save.click("work", _pt_code, _pt_category, _pt_tag, _pt_date, _pt_keyword, _prjCode, "");

        ajax_list("list");

        // $overlayForSearch.css("display","none"); 

    });

    $(".gnb0").click(function() {
        $(".contents2").hide();
        _pt_code = "2";

        paging_num = 0;
        paging_num_group = 0;
        paging_plus = 0;

        //카테고리별(Vcomm) 리스트 검색
        _pt_category = "";
        _pt_date = "";
        _pt_keyword = "";
        _pt_tag = "";
        _prjCode = "";

        // Log Insert
        vi_log_save.click("work", _pt_code, _pt_category, _pt_tag, _pt_date, _pt_keyword, _prjCode, "");

        ajax_list("list");
    });

    $(".gnb1").click(function() {
        $(".contents1").hide();
        _pt_code = "1";

        paging_num = 0;
        paging_num_group = 0;
        paging_plus = 0;

        //카테고리별(Vlab) 리스트 검색
        _pt_category = "";
        _pt_date = "";
        _pt_keyword = "";
        _pt_tag = "";
        _prjCode = "";

        // Log Insert
        vi_log_save.click("work", _pt_code, _pt_category, _pt_tag, _pt_date, _pt_keyword, _prjCode, "");

        ajax_list("list");
    });

    $(".nav_category>li").eq(1).click(function() {
        var tag_rowSection = ""; //태그 리스트 초기화
        $(".category_list2").empty();

        /*
        $.getJSON("/Ajax/vWorkTagList.aspx?pt_code=" + _pt_code + "", function (data) {
            for (i = 0; i < data.vinyl_tag.length; i++) {
                tag_rowSection = "<li tag='" + data.vinyl_tag[i].tag_name.trim() + "'><a href='#none' style='background-color: rgb(233, 233, 233); color: black;'>" + data.vinyl_tag[i].tag_name.trim() + "</a></li>";
                $(".category_list2").append(tag_rowSection);
            }

            tag_category_height();
            tag_category_motion();
            tag_search_list();
        });
		*/

        $.getJSON("/Ajax/work_test/tagList.json", function(data) {
            for (i = 0; i < data.vinyl_tag.length; i++) {
                tag_rowSection = "<li tag='" + data.vinyl_tag[i].tag_name.trim() + "'><a href='#none' style='background-color: rgb(233, 233, 233); color: black;'>" + data.vinyl_tag[i].tag_name.trim() + "</a></li>";
                $(".category_list2").append(tag_rowSection);
            }
            
            tag_category_motion();
            tag_search_list();
        });
    });

    var $tabNavButton = $('.section_list').find('li'),
        $sortBtn = $(".action_sort");

    //Product Tab List Click
    $tabNavButton.bind('click', function() {
        // 각 탭의 아이콘을 클릭하면

        var category = $(this).attr("data-category"),
            product_nav_index = $(this).index();

        $(".product_con>h2>a").text($(".section_list>li>a>div>span").eq(product_nav_index).text());
        $(".product_list>ul").empty();
        $('.related_list').empty();

        line_up(category);
        related_project(category);
    });
    // click

    //Product All Menu Btn Click
    $sortBtn.bind("click", function() {
        //전체 메뉴 닫기 버튼
        var category_idx = $(".section_list > li").length;
        for (i = 0; i < category_idx; i++) {
            line_up_all("C0" + i + "", i);
        }
        // for
    });

});